package StrUtils

import _ "strings"

// SIndex 查询是否切片包含元素，-1则不存在
func SIndex(codes []string, code string) int {
	for i := 0; i < len(codes); i++ {
		if codes[i] == code {
			return i
		}
	}
	return -1

}

// RStrDuplicates 字符串切片去重
func RStrDuplicates(s []string) []string {
	var result = make([]string, 0)
	for i := 0; i < len(s); i++ {
		if SIndex(result, s[i]) >= 0 {
			continue
		} else {
			result = append(result, s[i])
		}
	}
	return result
}

// FilterStr 过滤元素
func FilterStr(codes []string, code string) []string {
	for i := 0; i < len(codes); i++ {
		if codes[i] == code {
			codes = append(codes[:i], codes[i+1:]...)
		}
	}
	return codes
}
